﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chinaer.Model.Common;
using Chinaer.Core.Helper;

namespace Chinaer.Bll
{
    public class MenuSubCategory : Repository, IBll.IMenuSubCategory
    {
        IDao.IMenuSubCategoryDAO menuSubCategoryDAO = new Dao.MenuSubCategoryDAO();
        public List<DTO.MenuSubCategoryDTO> GetMenuSubCategoryByMenuCategoryID(string menuCategoryID)
        {
            List<Model.Entities.Model_MenuSubCategory> model_ListMenuSubCategory = menuSubCategoryDAO.GetMenuSubCategoryByMenuCategoryID(menuCategoryID);
            List<DTO.MenuSubCategoryDTO> listMenuSubCategoryDTO = new List<DTO.MenuSubCategoryDTO>();
            lock (model_ListMenuSubCategory)
            {
                foreach (var item in model_ListMenuSubCategory)
                {
                    DTO.MenuSubCategoryDTO menuSubCategoryDTO = new DTO.MenuSubCategoryDTO();
                    Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(item, menuSubCategoryDTO);
                    listMenuSubCategoryDTO.Add(menuSubCategoryDTO);
                }
            }
            return listMenuSubCategoryDTO;
        }

        public List<DTO.MenuSubCategoryDTO> GetMenuSubCategoryByMenuCategoryIDAndDianPuID(string menuCategoryID, string dianPuID)
        {
            List<Model.Entities.Model_MenuSubCategory> model_ListMenuSubCategory = menuSubCategoryDAO.GetMenuSbCategoryByCategoryIDAndDianPuID(menuCategoryID, dianPuID);
            List<DTO.MenuSubCategoryDTO> listMenuSubCategoryDTO = new List<DTO.MenuSubCategoryDTO>();
            lock (model_ListMenuSubCategory)
            {
                foreach (var item in model_ListMenuSubCategory)
                {
                    DTO.MenuSubCategoryDTO menuSubCategoryDTO = new DTO.MenuSubCategoryDTO();
                    Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(item, menuSubCategoryDTO);
                    listMenuSubCategoryDTO.Add(menuSubCategoryDTO);
                }
            }
            return listMenuSubCategoryDTO;
        }

        public JsonResult Add(DTO.MenuSubCategoryDTO t)
        {
            if (t.CheckIsNull().Success == false)
            {
                return t.CheckIsNull();
            }
            JsonResult jsonResult = new JsonResult();
            Model.Entities.Model_MenuSubCategory model_MenuSubCategory = new Model.Entities.Model_MenuSubCategory();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(t, model_MenuSubCategory);
            if (string.IsNullOrEmpty(model_MenuSubCategory.ID) || model_MenuSubCategory.ID.Trim() == "")
            {
                model_MenuSubCategory.ID = Chinaer.Core.Helper.GenerateIDHelper.GenerateID();
            }
            jsonResult.Success = menuSubCategoryDAO.Add(model_MenuSubCategory);
            return jsonResult;
        }

        public JsonResult Delete(DTO.MenuSubCategoryDTO t)
        {
            JsonResult jsonResult = new JsonResult();
            Model.Entities.Model_MenuSubCategory model_MenuSubCategory = new Model.Entities.Model_MenuSubCategory();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(t, model_MenuSubCategory);
            jsonResult.Success = menuSubCategoryDAO.Delete(model_MenuSubCategory);
            return jsonResult;
        }

        public JsonResult Delete(string id)
        {
            JsonResult jsonResult = new JsonResult();
            jsonResult.Success = menuSubCategoryDAO.Delete(id);
            return jsonResult;
        }

        public JsonResult Update(DTO.MenuSubCategoryDTO t)
        {
            if (t.CheckIsNull().Success == false)
            {
                return t.CheckIsNull();
            }
            JsonResult jsonResult = new JsonResult();
            Model.Entities.Model_MenuSubCategory model_MenuSubCategory = new Model.Entities.Model_MenuSubCategory();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(t, model_MenuSubCategory);
            jsonResult.Success = menuSubCategoryDAO.Update(model_MenuSubCategory);
            return jsonResult;
        }

        public DTO.MenuSubCategoryDTO GetByID(string id)
        {
            Model.Entities.Model_MenuSubCategory menuSubCategory = menuSubCategoryDAO.GetByID(id);
            DTO.MenuSubCategoryDTO menuSubCategoryDTO = new DTO.MenuSubCategoryDTO();
            Chinaer.Core.Helper.DTOtoEntityObjectHelper.Instance.DTOtoEntityObject(menuSubCategory, menuSubCategoryDTO);
            return menuSubCategoryDTO;
        }
    }
}
